package models.spider.policy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
 * 
 * @author laurent@opprecht.info
 */
public class Whitelist extends Policy {

	protected List<String> entries = new ArrayList<String>();

	public Whitelist(final List<String> entries) {
		this.entries = entries;
	}

	public Whitelist(final String... entries) {
		this.entries = Arrays.asList(entries);
	}

	List<String> getEntries() {
		return this.entries;
	}

	@Override
	public boolean accept(final String url) {
		for (String entry : entries) {
			if (Pattern.matches(entry, url)) {
				return true;
			}
		}
		return false;
	}
}
